前言:昨天發現旅遊app中有一個功能是可以把整頁的TableView水平滑動,越看功能越多越來越複雜,其實裡面還有一些配合按鈕滑動整個TableView,但這個我目前毫無想法,所以就先試做簡單的TableView可以整頁向左滑,另外也要感謝團隊成員的幫忙,才找到我的問題,這次的bug卡很久啊。
let mainStoryboard = UIStoryboard(name: "Main", bundle: nil)
let firstViewController = mainStoryboard.instantiateViewController(withIdentifier: "firstTableView") as! FirstViewController
let secondViewController = mainStoryboard.instantiateViewController(withIdentifier: "secondTableView") as! SecondViewController
var frame2ForSecondViewController = secondViewController.view.frame
frame2ForSecondViewController.origin.x = self.view.frame.size.width
secondViewController.view.frame = frame2ForSecondViewController
self.addChildViewController(firstViewController)
self.myScrollView.addSubview(firstViewController.view)
firstViewController.didMove(toParentViewController: self)
self.addChildViewController(secondViewController)
self.myScrollView.addSubview(secondViewController.view)
secondViewController.didMove(toParentViewController: self)
//設定UIScrollView的大小
myScrollView.contentSize = CGSize(width: self.view.frame.width * 2, height: self.view.frame.height)